package com.chinaisafe.user.controller;

import com.chinaisafe.base.common.annotation.OperationLog;
import com.chinaisafe.base.common.enums.BusinessTypeEnum;
import com.chinaisafe.base.common.validated.AddGroup;
import com.chinaisafe.base.common.validated.QueryGroup;
import com.chinaisafe.base.common.validated.UpdateGroup;
import com.chinaisafe.base.common.vo.Answer;
import com.chinaisafe.module.user.request.RoleMenuReqVO;
import com.chinaisafe.user.biz.SysRoleMenuBiz;
import com.chinaisafe.user.vo.request.SysRoleMenuReqVO;
import com.chinaisafe.user.vo.response.SysMenuRespVO;
import com.chinaisafe.user.vo.response.SysRoleMenuRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * SysRoleMenuController
 * Description：角色与菜单接口层
 *
 * @author xuefu.shu
 * @date  2024-07-13 17:14:06
 */
@RestController
@RequestMapping("sysRoleMenu")
@Tag(name = "角色与菜单接口层", description = "角色与菜单接口层")
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuBiz sysRoleMenuBiz;

    @GetMapping("allMenuTree")
    @Operation(summary = "获取应用的菜单", description = "分配角色菜单权限时调用")
    public Answer<List<SysMenuRespVO>> allMenuTree(@Validated(QueryGroup.class) SysRoleMenuReqVO sysRoleMenuReqVO) {
        List<SysMenuRespVO> pageList = sysRoleMenuBiz.allMenuTree(sysRoleMenuReqVO);
        return Answer.success("获取成功", pageList);
    }

    @GetMapping("myMenuTree")
    @Operation(summary = "获取我的菜单", description = "进入应用后调用")
    public Answer<List<SysMenuRespVO>> myMenuTree(Long sysAppId, Long sysModuleId) {
        List<SysMenuRespVO> pageList = sysRoleMenuBiz.myMenuTree(sysAppId,sysModuleId);
        return Answer.success("获取成功", pageList);
    }

    @PostMapping()
    @Operation(summary = "新增角色与菜单", description = "新增角色与菜单")
    @OperationLog(title = "角色与菜单-新增", businessType = BusinessTypeEnum.INSERT)
    public Answer<Void> roleUpdateMenu(@RequestBody @Validated(UpdateGroup.class) RoleMenuReqVO sysRoleMenuReqVO) {
        sysRoleMenuBiz.roleUpdateMenu(sysRoleMenuReqVO);
        return Answer.success("保存成功");
    }






}

